package cfca.seal.web.service;

import cfca.seal.bean.AdminUser;
import cfca.seal.common.Page;
import cfca.seal.dao.main.IAdminUserDao;
import cfca.seal.exception.CodeException;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class ManagerService
{

  @Resource
  private IAdminUserDao managerDao;

  public AdminUser getManagerByName(String name)
    throws Exception
  {
    AdminUser manger = this.managerDao.getManagerByUsername(name);
    return manger;
  }

  public AdminUser getManagerById(String id) throws Exception {
    AdminUser manger = this.managerDao.getManagerById(id);
    return manger;
  }

  public Page<AdminUser> getManagers(String pageNo) throws Exception {
    Page page = this.managerDao.getPage(pageNo);

    return page;
  }

  public boolean addManager(AdminUser user) throws Exception {
    AdminUser adminUser = this.managerDao.getManagerByUsername(user.getName());
    if (adminUser != null) {
      throw new CodeException("C9009", "已存在用户名相同的用户");
    }
    return this.managerDao.insert(user);
  }

  public boolean update(AdminUser user) throws Exception {
    return this.managerDao.update(user);
  }

  public boolean deleteById(String deleteId) throws Exception {
    return this.managerDao.deleteById(deleteId);
  }

  public boolean loginUpdate(AdminUser manager) throws Exception {
    return this.managerDao.loginUpdate(manager);
  }

  public AdminUser getAdminUserByDnAndSn(String certDN, String certSN) throws Exception {
    return this.managerDao.getAdminUser(certDN, certSN);
  }
}